var myWindow;

/*
	Function: IsNullValue 
	Purpose: Check null value of the selected field
	Input: object need IsNullValue
	Output: True if value if null
*/

function IsNullValue(obj){
    strValue=eval(obj).value;
    if (strValue == "") {
       return true;
    } else {
      blnStatus = true;
      for (intIndex = 0; intIndex < strValue.length; intIndex++) {
        if (strValue.charAt(intIndex) != " ") {
           blnStatus = false;
           break;
        }
      }         
      return blnStatus;
    }
}

/*
	Function: IsValidNumber
	Purpose: Check a variable is positive number
	Input: object need check
	Output: True if value if positive number
*/
function IsValidNumber(objDateField, strMsg) {
	var objNumber;
	objNumber = eval(objDateField).value;
	if ((isNaN(objNumber)) || (IsNullValue(objDateField))) {
		alert(strMsg);
		eval(objDateField).value = "";
		eval(objDateField).focus();
		return false;
	}
	if (parseFloat(objNumber) < 0) {
		return false;
	}
	return true;
}

/*
	Function: IsValidDate
	Purpose: Check value is valid date
	Input: object need check, dateformat
	Output: True if value if valid
*/
function IsValidDate(objDateField, strDateFormat, strMsg){
	strDateFormat = strDateFormat.toLowerCase();
	strDate = eval(objDateField).value;
	switch(strDateFormat){
		case 'dd/mm/yyyy':
			if (strDate != "") {
				strDay = strDate.substring(0, strDate.indexOf("/"));
				strMonth = strDate.substring(strDate.indexOf("/") + 1, strDate.lastIndexOf("/"));
				strYear = strDate.substring(strDate.lastIndexOf("/") + 1, strDate.length);
				dtmDate = new Date (strMonth + "/" + strDay + "/" + strYear);
				intDay = dtmDate.getDate();
				intMonth = dtmDate.getMonth() + 1;
				intYear = dtmDate.getYear();
				if ((parseFloat(strDay) != parseFloat(intDay)) || (parseFloat(strMonth) != parseFloat(intMonth)) || (isNaN(strYear)) || (strYear.length < 4)) {
					alert(strMsg);
					eval(objDateField).value = "";
					eval(objDateField).focus();
					return false;
				}
				break;
			}	
		case 'mm/dd/yyyy':
			if (strDate != "") {
				strMonth = strDate.substring(0, strDate.indexOf("/"));
				strDay = strDate.substring(strDate.indexOf("/") + 1, strDate.lastIndexOf("/"))
				strYear = strDate.substring(strDate.lastIndexOf("/") + 1, strDate.length);
				dtmDate = new Date (strMonth + "/" + strDay + "/" + strYear);
				intDay = dtmDate.getDate();
				intMonth = dtmDate.getMonth() + 1;
				intYear = dtmDate.getYear();
				if (parseFloat(strDay) != parseFloat(intDay) || parseFloat(strMonth) != parseFloat(intMonth)|| (strYear != intYear)) {
					alert(strMsg);
					eval(objDateField).value = "";
					eval(objDateField).focus();
					return  false;
				}		
				break;
			}
	}
	return true;
}

/*
	Function: OpenWin
	Purpose: Open new windows
*/
function OpenWin(strURL, strWinName, intWidth, intHeight, intLeft, intTop){
	myWindow = window.open(strURL, strWinName, "width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft+ ",top=" + intTop+ ",menubar=no,resizable=yes,scrollbars=yes");
	myWindow.focus();
}

/*
	Function: CloseWin
	Purpose: Close windows
*/
function CloseWin(){
	window.Close();
}

function OpenWinCenter(windowHeight, windowWidth, windowName, windowUri)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=yes,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);

    newWindow.focus();
    return newWindow.name;
}
function OpenWinCenterClose(windowHeight, windowWidth, windowName, windowUri)
{
	window.close();
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=yes,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight  + ",menubar=no,resizable=yes,scrollbars=yes");

    newWindow.focus();
    return newWindow.name;
}


/*
	Function: Esc
*/
function Esc(strSource) {
	strSource = escape(strSource);
	strDes = "";
	while (strSource.length > 0) {
		intPos = strSource.indexOf("%"); 
		if (intPos >= 0) {
			if (strSource.charAt(intPos + 1) == "u") {
				strDes = strDes + strSource.substring(0, intPos) + JStoURLEncode(eval("0x" + strSource.substring(intPos + 2, intPos + 6)));
				strSource = strSource.substring(intPos +6, strSource.length);
			} else {
				strDes = strDes + strSource.substring(0, intPos) + JStoURLEncode(eval("0x" + strSource.substring(intPos + 1, intPos + 3)));
				strSource = strSource.substring(intPos + 3, strSource.length);
			}
		} else {
			strDes = strDes + strSource;
			strSource = "";
		}
	}
	return strDes;
}

/*
	Function: JStoURLEncode
*/
function JStoURLEncode(c) {
	if (c < 0x80) {
	    return Hexamize(c);
	} else if (c < 0x800) {
		return Hexamize(0xC0 | c>>6) + Hexamize(0x80 | c & 0x3F);
    } else if (c < 0x10000) {
		return Hexamize(0xE0 | c>>12) + Hexamize(0x80 | c>>6 & 0x3F) + Hexamize(0x80 | c & 0x3F);
    } else if (c < 0x200000) {
		return Hexamize(0xF0 | c>>18) + Hexamize(0x80 | c>>12 & 0x3F) + Hexamize(0x80 | c>>6 & 0x3F) + Hexamize(0x80 | c & 0x3F);
    } else {
		return '?'
    }
}

/*
	Function: Hexamize
*/
function Hexamize(n) {
	hexstr = "0123456789ABCDEF";
	return "%" + hexstr.charAt(parseInt(n/16)) + hexstr.charAt(n%16);
}

/*
	Function: GenRandomNumber
	Purpose: Generate random number
*/
function GenRandomNumber(intNumber) {
	var intCount;
	var strOutput = '';
	
	for(intCount = 1; intCount <= intNumber; intCount++){ 
		strOutput = strOutput + (String)(parseInt(9 * Math.random()+48));
	}
	return strOutput;
}

/*
	Function: GenURLImg
	Purpose: set image source
*/
function GenURLImg(intNumber){
	if (document.images["Image1"]) {
		document.images["Image1"].src = '../Common/WShowStat.aspx?Num=1&x=' + GenRandomNumber(intNumber);
	}
	if (document.images["Image2"]) {
		document.images["Image2"].src = '../Common/WShowStat.aspx?Num=2&x=' + GenRandomNumber(intNumber);
	}
	if (document.images["Image3"]) {
		document.images["Image3"].src = '../Common/WShowStat.aspx?Num=3&x=' + GenRandomNumber(intNumber);
	}
	if (document.images["Image4"]) {
		document.images["Image4"].src = '../Common/WShowStat.aspx?Num=4&x=' + GenRandomNumber(intNumber);
	}
	if (document.images["Image5"]) {
		document.images["Image5"].src = '../Common/WShowStat.aspx?Num=5&x=' + GenRandomNumber(intNumber);
	}
	if (document.images["Image6"]) {
		document.images["Image6"].src = '../Common/WShowStat.aspx?Num=6&x=' + GenRandomNumber(intNumber);
	}
}

/*
	Function: RemoveSpace
	Purpose: Remove space
*/
function RemoveSpace(strInput) {
    var strValue=strInput;
    var strOutput = '';
    if (strValue == "") {
		return true;
    } else {
		for (intIndex = 0; intIndex < strValue.length; intIndex++) {
			if (strValue.charAt(intIndex) != " ") {
				strOutput = strOutput + strValue.charAt(intIndex);
			}
		}
		return strOutput;
    }
}

function OpenFullWin(strURL, strWinName){
	myWindow = window.open(strURL, strWinName, ",menubar=no,resizable=yes,scrollbars=yes,fullsize=yes");
	myWindow.focus();
}

function Goto(me,page)
{
	var strCode  = me.options[me.selectedIndex].value;
	window.location.href = page + '.aspx?Code=' + strCode;
}




